﻿// -----------------------------------------------------------------------
// <copyright file="Logger.cs" company="None">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
using System.IO;
using System;
namespace ODataRegression.Framework.Core.Shared
{
    public class Logger
    {
        string logFileName;

        public Logger(string logFileName)
        {
            this.logFileName = logFileName;
        }
        public void LogInformation(string message)
        {
            TextWriter tw = new StreamWriter(logFileName, true);

            // write a line of text to the file
            tw.WriteLine(String.Format("{0}:{1}", DateTime.Now.ToString(), message));

            tw.Close();
            tw.Dispose();
        }

        public void LogException(Exception e)
        {
            if (e != null)
            {
                TextWriter tw = new StreamWriter(logFileName, true);

                // write a line of text to the file
                tw.WriteLine(String.Format("{0}:{1}", DateTime.Now.ToString(), e.Message));
                tw.WriteLine(e.StackTrace);
                if (e.InnerException != null)
                {
                    tw.WriteLine(e.InnerException.Message);
                    tw.WriteLine(e.InnerException.StackTrace);

                }
                // close the stream
                tw.Close();
                tw.Dispose();
            }

        }

    }
}
